<template>
  <div class="app-container home">
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="24" :sm="24" :lg="8" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('messages')">
          <div class="card-panel-icon-wrapper icon-message">
            <i class="el-icon-s-custom card-panel-icon"/>
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              老人总数
            </div>
            <count-to :start-val="0" :end-val="customerCount" :duration="1000" :decimals="0" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('newVisitis')">
          <div class="card-panel-icon-wrapper icon-people">
            <svg-icon icon-class="peoples" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              服务人员总数
            </div>
            <count-to :start-val="0" :end-val="serviceUserCount" :duration="1000" class="card-panel-num" />
          </div>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8" class="card-panel-col">
        <div class="card-panel" @click="handleSetLineChartData('shoppings')">
          <div class="card-panel-icon-wrapper icon-shopping">
            <i class="el-icon-postcard card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              服务总次数
            </div>
            <count-to :start-val="0" :end-val="serviceCount" :duration="1000" class="card-panel-num" />
          </div>
        </div>
      </el-col>

    </el-row>
    <el-divider />
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="24" :sm="24" :lg="8" class="card-panel-col">
        <pie-chart title="老人性别占比" :chart-data="customerSex"/>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8" class="card-panel-col">
        <pie-chart title="老人失能等级占比"  :chart-data="disabilityType"/>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8" class="card-panel-col">
        <pie-chart  title="服务项目占比"  :chart-data="serviceType"/>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import CountTo from 'vue-count-to'
import PieChart from './dashboard/PieChart'
import { groupBySex,groupByDisabilityType,groupByServiceItemId,queryCustomerCount,queryServiceUserCount,queryServiceCount} from "@/api/dashboard/dashboard";
export default {
  name: "Index",
  components: {
    CountTo,
    PieChart
  },
  data() {
    return {
      customerCount:0,
      serviceUserCount:0,
      serviceCount:0,
      customerSex:[{ "name": "男", "value": 0 }, { "name": "女", "value": 0 } ],
      disabilityType:[],
      serviceType:[],
      // 版本号
      version: "4.3.1",
    };
  },
  created() {
    this.getCustomerSexData();
    this.getDisabilityTypeData();
    this.getServiceTypeData();
    this.getCustomerCount();
    this.getServiceUserCount();
    this.getServiceCount();
  },
  methods: {
    goTarget(href) {
      window.open(href, "_blank");
    },
    //获取老人总数
    getCustomerCount(){
      queryCustomerCount().then(response => {
        this.customerCount = response.data;
      });
    },
    //获取服务人员总数
    getServiceUserCount(){
      queryServiceUserCount().then(response => {
        this.serviceUserCount = response.data;
      });
    },
    //获取服务总次数
    getServiceCount(){
      queryServiceCount().then(response => {
        this.serviceCount = response.data;
      });
    },
    //获取性别数据
    getCustomerSexData(){
      let that = this;
      groupBySex().then(response => {
        let sexData = response.data;
        that.customerSex = [];
        sexData.forEach(function (item,index,array) {
          if(item.customer_sex=='0'){
            that.customerSex.push({"name":"男","value":item.count});
          }else{
            that.customerSex.push({"name":"女","value":item.count});
          }
        })
      });
    },
    //获取失能数据
    getDisabilityTypeData(){
      groupByDisabilityType().then(response => {
        this.disabilityType = response.data;
      });
    },
    //获取服务项目数据
    getServiceTypeData(){
      groupByServiceItemId().then(response => {
        this.serviceType = response.data;
      });
    }
  },
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}

.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3
      }


    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}
</style>

